<?php
namespace app\admin\controller;
use think\Db;
use lib\Curl;
class Tiktok extends Base{
    //广告图
    public function tiktok_banner(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('tiktok_banner')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['banner']=$param['banner'];
            $res= Db::name('tiktok_banner')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200,'msg' => '更新成功']);
            }else{
                return json(['code' => 500,'msg' => '失败']);
            }
        }
    }
    public function tiktok_operative_title(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('tiktok_operative_title')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['subtitle']=$param['subtitle'];
            $res=Db::name('tiktok_operative_title')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function tiktok_operative(){
        $list=Db::name('tiktok_operative')->order('id desc')->paginate(10);
        $counts=Db::name('tiktok_operative')->count();
        $data=$list->all();
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('counts',$counts);
        return $this->fetch();
    }
    public function tiktok_operative_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['icon']=$param['icon'];
            $data['sort']=$param['sort'];
            $res= Db::name('tiktok_operative')->insertGetId($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function tiktok_operative_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('tiktok_operative')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['icon']=$param['icon'];
            $data['sort']=$param['sort'];
            $res=Db::name('tiktok_operative')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function tiktok_operative_del(){
        $param = input('post.');
        $res= Db::name('tiktok_operative')->where(array('id'=>$param['id']))->delete();
        return json(['code' => 200,'msg' => '删除成功']);

    }

    public function tiktok_keepup_title(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('tiktok_keepup_title')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['subtitle']=$param['subtitle'];
            $res=Db::name('tiktok_keepup_title')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function tiktok_keepup(){
        $list=Db::name('tiktok_keepup')->order('id desc')->paginate(10);
        $counts=Db::name('tiktok_keepup')->count();
        $data=$list->all();
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('counts',$counts);
        return $this->fetch();
    }
    public function tiktok_keepup_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['icon']=$param['icon'];
            $data['sort']=$param['sort'];
            $res= Db::name('tiktok_keepup')->insertGetId($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function tiktok_keepup_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('tiktok_keepup')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['icon']=$param['icon'];
            $data['sort']=$param['sort'];
            $res=Db::name('tiktok_keepup')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function tiktok_keepup_del(){
        $param = input('post.');
        $res= Db::name('tiktok_keepup')->where(array('id'=>$param['id']))->delete();
        return json(['code' => 200,'msg' => '删除成功']);

    }


    public function tiktok_fiveelements_title(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('tiktok_fiveelements_title')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['subtitle']=$param['subtitle'];
            $res=Db::name('tiktok_fiveelements_title')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function tiktok_fiveelements(){
        $list=Db::name('tiktok_fiveelements')->order('id desc')->paginate(10);
        $counts=Db::name('tiktok_fiveelements')->count();
        $data=$list->all();
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('counts',$counts);
        return $this->fetch();
    }
    public function tiktok_fiveelements_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['sort']=$param['sort'];
            $res= Db::name('tiktok_fiveelements')->insertGetId($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function tiktok_fiveelements_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('tiktok_fiveelements')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['sort']=$param['sort'];
            $res=Db::name('tiktok_fiveelements')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function tiktok_fiveelements_del(){
        $param = input('post.');
        $res= Db::name('tiktok_fiveelements')->where(array('id'=>$param['id']))->delete();
        return json(['code' => 200,'msg' => '删除成功']);

    }
    public function tiktok_operaprocess(){
        $list=Db::name('tiktok_operaprocess')->order('id desc')->paginate(10);
        $counts=Db::name('tiktok_operaprocess')->count();
        $data=$list->all();
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('counts',$counts);
        return $this->fetch();
    }
    public function tiktok_operaprocess_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['sort']=$param['sort'];
            $res= Db::name('tiktok_operaprocess')->insertGetId($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function tiktok_operaprocess_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('tiktok_operaprocess')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['sort']=$param['sort'];
            $res=Db::name('tiktok_operaprocess')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function tiktok_operaprocess_del(){
        $param = input('post.');
        $res= Db::name('tiktok_operaprocess')->where(array('id'=>$param['id']))->delete();
        return json(['code' => 200,'msg' => '删除成功']);

    }
}